﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Solution739
{
    public int[] DailyTemperatures(int[] temperatures)
    {
        Stack<int> s = new Stack<int>();//存放index
        int[] res= new int[temperatures.Length];

        
        for (int i = 0; i < temperatures.Length; i++)
        {
           


            //if(s.Count==0||temperatures[i] <= temperatures[s.Peek()])
            //{
            //    s.Push(i);
            //}
            //else
            //{
                while (s.Count != 0&&temperatures[i] > temperatures[s.Peek()])
                {

                 int top=   s.Pop();
                    res[top] = i - top;

                   
                }

                s.Push(i);
            //}
           


        }
        return res;

    }
}

class Program739
{
    static void Main739(string[] args)
    {
        Solution739 solution739 = new Solution739();
        int[] temperatures = [73, 74, 75, 71, 69, 72, 76, 73];
        int[] res= solution739.DailyTemperatures(temperatures);

        for (int i = 0; i < res.Length; i++)
        {
            Console.WriteLine(res[i]);
        }
    }
}
